home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / XCMDs and XFCNs / MakeTable XFCN / MakeTable.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-17  |  1.5 KB  |  60 lines  |  [TEXT/MPS ]

  1. /*
  2.     MakeTable    - XFCN to compress runs of spaces and tabs to a space
  3. */
  4.  
  5. #define    whoami    "\n\
  6. --- MakeTable(string), Version 1.0, February 1993,\n\
  7.     by Eric Gundrum, based on Reduce by Dan Allen.\n\
  8.     Converts runs of spaces & tabs to a single tab in the passed string.\n"
  9.  
  10. #include <Types.h>
  11. #include <Memory.h>
  12. #include <String.h>
  13. #include <HyperXCmd.h>
  14.  
  15. #define ReturnError(x)    {paramPtr->returnValue=msgHandle(x);return;}
  16.  
  17. Handle msgHandle(char* msg_string);
  18.  
  19. pascal void EntryPoint(XCmdPtr paramPtr)
  20. {
  21.     char        *sourceChar,*resultChar;
  22.     Handle        Result_hdl;
  23.  
  24.     if(paramPtr->paramCount != 1)
  25.         ReturnError("List of parameters is not usable.");
  26.     MoveHHi(paramPtr->params[0]);
  27.     Result_hdl = NewHandle(GetHandleSize(paramPtr->params[0]));
  28.     if (!Result_hdl)
  29.         ReturnError("Could not allocate space for table.")
  30.     HLock(Result_hdl);
  31.     sourceChar = *(paramPtr->params[0]);
  32.     resultChar = *Result_hdl;
  33.     while(*sourceChar)
  34.     {
  35.         if (*sourceChar == '\t' || *sourceChar == ' ')
  36.         {
  37.             do
  38.                 sourceChar++;
  39.             while (*sourceChar == '\t' || *sourceChar == ' ');
  40.             *resultChar++ = '\t';
  41.         } else
  42.             *resultChar++ = *sourceChar++;
  43.     }
  44.     *resultChar = '\0';
  45.     SetHandleSize(Result_hdl,strlen(*Result_hdl));
  46.     paramPtr->returnValue = Result_hdl;
  47.     HUnlock(Result_hdl);
  48. }
  49.  
  50. Handle msgHandle(char* msg_string)
  51. {
  52.     Handle returnMsg = NewHandle(strlen(msg_string) + strlen(whoami) + 1);
  53.  
  54.     HLock(returnMsg);
  55.     BlockMove(msg_string,*returnMsg,strlen(msg_string)); 
  56.     BlockMove(whoami,*returnMsg+strlen(msg_string),strlen(whoami));
  57.     HUnlock(returnMsg);
  58.     return returnMsg;
  59. }
  60.